% print entries commented out marked %%**

disp('Commands to compute stuff')
disp(' ')

set(text,'FontSize',2);

% ************************************
% Some model parameters we will need
% ************************************
% delta=0.96
% q0=.01
% q0=1.0/(q0+1.0)
% debtfactor=1.0/((1.0-q0*delta)*4.0)

filename = 'dataf\d2param.dat';
delimiterIn = ' ';
headerlinesIn = 1;
myparam = importdata(filename,delimiterIn,headerlinesIn);
myparam.data;
myparam;
myparam.textdata;

delta=myparam.data(:,1);
q0=myparam.data(:,2);
freq=myparam.data(:,3);
debtfactor=1.0/((1.0-q0*delta)*freq);


% *************************************************
% PRICES
% *************************************************

amin= 0.00;
amax= 0.28*debtfactor %0.60;

zmin = 0.00;
zmax = 7.01;

% For z=1

mydata = importdata('dataf\d2Q_z1.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;

asset= mydata.data(:,1)*debtfactor;
qq= mydata.data(:,2);
qqdef= mydata.data(:,3);


% figure(1); 
% subplot(1,1,1);
% plot(asset, qq,'b-','LineWidth',2.0); 
% ylabel(' Q'); 
% xlabel('Debt A next'); 
% %title('(a) Initial prices ');
% title(mydata.textdata(1,1));
% legend ('Q menu, zero def');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% print -djpeg slides\qmenu_z1.jpg


% For various z

mydata = importdata('dataf\d2Q_z3.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
qqz3= mydata.data(:,2);
qqdefz3= mydata.data(:,3);

mydata = importdata('dataf\d2Q_z5.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
qqz5= mydata.data(:,2);
qqdefz5= mydata.data(:,3);

mydata = importdata('dataf\d2Q_z6.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
qqz6= mydata.data(:,2);
qqdefz6= mydata.data(:,3);

mydata = importdata('dataf\d2Q_z9.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
qqz9= mydata.data(:,2);
qqdefz9= mydata.data(:,3);


% % figure(1); 
% % subplot(1,1,1);
% % plot(asset, qq,'b-',asset, qqz3,'b--',asset, qqz6,'b-.',asset, qqz9,'b*-','LineWidth',2.0); 
% % ylabel(' Q'); 
% % xlabel('Total debt next period/Y'); 
% % %title('(a) Initial prices ');
% % title('Debt prices (case D=0)' );
% % legend ('Q z1', 'Q z3', 'Q z6', 'Q z9');
% % %axis([-.01 amax, -.1 .9 ]);
% % axis([amin amax, zmin zmax]);
% % 
% % %%**print -djpeg slides\qmenu.jpg




% % --------------------------------------
% % Def 0 and >0, for z=5, d
% % --------------------------------------
% mydata = importdata('dataf\d2Q_z1.dat', ' ', 2);
% mydata.data;
% mydata;
% mydata.textdata;
% 
% asset= mydata.data(:,1);
% qq= mydata.data(:,2);
% qqdef= mydata.data(:,3);
% 
% 
% 
% 
% amin= 0.00;
% amax= 0.10 %0.60;
% 
% zmin = 0.00;
% zmax = 20.01;
% 
% 
% 
% figure(1); 
% subplot(1,1,1);
% plot(asset, qq,'b-',asset, qqdef,'g--','LineWidth',2.0); 
% ylabel(' Q'); 
% xlabel('Debt A next'); 
% %title(mydata.textdata(1,1));   %('(a) Initial prices ');
% title('Debt prices (case D=0 and D>0)' );
% legend ('Q no def', 'Q def>0');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% 
% print -djpeg slides\qdef.jpg
% 

% *************************************************
% SPREADS, WITH NO DEF AND POSITIVE DEF
% *************************************************

zmin = 0.005;
zmax = .25;
amin= 0.00;
amax= 0.22*debtfactor %0.60;

%q0=1/(1+0.01)
%delta= 0.96

sprz=qq
sprdef=qqdef
sprz3=qq
sprdefz3=qqdef
sprz6=qq
sprdefz6=qqdef



sprz(:)=(((1./qq(:))+delta).^freq)-((1/q0)^freq)
sprdef(:)=(((1./qqdef(:))+delta).^freq)-((1/q0)^freq)

sprz3(:)=(((1./qqz3(:))+delta).^freq)-((1/q0)^freq)
sprdefz3(:)=(((1./qqdefz3(:))+delta).^freq)-((1/q0)^freq)


sprz6(:)=(((1./qqz6(:))+delta).^freq)-((1/q0)^freq)
sprdefz6(:)=(((1./qqdefz6(:))+delta).^freq)-((1/q0)^freq)


figure(2); 
subplot(1,1,1);
plot(asset, sprz6,'r--',asset, sprz3,'b-', asset, sprdefz3,'b-.','LineWidth',2.0); 
%***plot(asset, sprz5,'k-',asset,sprdefz5,'k-.',asset, sprz3,'b-', asset, sprdefz3,'b-.',asset, sprz,'r-', asset, sprdef,'r-.','LineWidth',2.0); 
ylabel(' spread'); 
xlabel('Total debt next period/Y '); 
%title(mydata.textdata(1,1));   %('(a) Initial prices ');
%title('Spread (case D=0 and D .52)' );
%***legend ('z5 nodef', 'z5 def 52%','z3 nodef', 'z3 def 52%','z1 nodef', 'z1 def 52%','Location','northwest');
legend ('z5 nodef', 'z3 nodef', 'z3 def 100%','Location','northwest');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

%%**
print -djpeg slides\sprmenu.jpg


zmin = 0.005;
zmax = .25;
amin= 0.00;
amax= 0.20*debtfactor ;

% Pic 2 for paper
% % figure(20); 
% % set(gca,'FontSize',18)
% % plot(asset, sprz5,'r--',asset, sprz3,'b-', asset, sprdefz3,'k-.','LineWidth',2.0); 
% % text(asset(13),sprz5(13),'spr(z5,a'',d=0)','FontSize',16,'Color','r')
% % text(asset(5),sprz5(15),'spr(z3,a'',d=1)','FontSize',16,'Color','k')
% % text(asset(7),sprz5(17),'spr(z3,a'',d=0)','FontSize',16,'Color','b')
% % ylabel(' Spread'); 
% % xlabel('Total Debt to Output Next Period'); 
% % axis([amin amax, zmin zmax]);
% % 
% % 
% % plot(asset, defz3,'b-',asset, defz5,'r--','LineWidth',2);
% % text(asset(8),defz3(13),'D(A,z3)','FontSize',18,'Color','b')
% % text(asset(15),defz3(8),'D(A,z5)','FontSize',18,'Color','r')
% % 
% % 
% % print -djpeg slides\sprmenu.jpg


% % SPREADS
% 
% %amin= 0.05;
% %amax= 0.06 %0.60;
% %zmin = 13.00;
% %zmax = 14.01;
% %(((one/qqqtil)+delta)**4.0_prec)-((one/q0)**4.0_prec)
% 
% q0=1/(1+0.01)
% delta= 0.96
% 
% spr=qq
% sprdef=qqdef
% 
% 
% spr(:)=(((1./qq(:))+delta).^4.0)-((1/q0)^4.0)
% sprdef(:)=(((1./qqdef(:))+delta).^4.0)-((1/q0)^4.0)
% zmin = 0.005;
% zmax = .04;
% amin= 0.00;
% amax= 0.06 %0.60;
% 
% figure(1); 
% subplot(1,1,1);
% plot(asset, spr,'b-',asset, sprdef,'g--','LineWidth',2.0); 
% ylabel(' Q'); 
% xlabel('Debt A next'); 
% %title(mydata.textdata(1,1));   %('(a) Initial prices ');
% title('Spread (case D=0 and D .75)' );
% legend ('spr no def', 'spr def>0');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% 
% print -djpeg slides\sprdef.jpg


% *************************************************
% POLICY RULES
% *************************************************%

amin= 0.00;
amax= 0.22*debtfactor; % 0.16; %0.60; %136;

% --------------------------------------
% For z=1
% --------------------------------------

mydata = importdata('dataf\d2Apr_z1.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;

asset= mydata.data(:,1)*debtfactor;
A= mydata.data(:,1)*debtfactor;
Apr=   mydata.data(:,2)*debtfactor;
def=   mydata.data(:,3);
b=   mydata.data(:,4);
q=   mydata.data(:,5);
v=   mydata.data(:,6);

Aprminus=   mydata.data(:,7)*debtfactor;
defminus=   mydata.data(:,8);
bminus=   mydata.data(:,9);
qminus=   mydata.data(:,10);
vminus=   mydata.data(:,11);

Aprplus=   mydata.data(:,12)*debtfactor;
defplus=   mydata.data(:,13);
bplus=   mydata.data(:,14);
qplus=   mydata.data(:,15);
vplus=   mydata.data(:,16);




% Debt service

zmin = 0.00;
zmax = 0.18*debtfactor %08; %0.60; %0.135;
% % figure(3); 
% % subplot(1,1,1);
% % %plot(asset,A,'k--',asset, Apr,'r-',asset, Aprminus,'b-',asset, Aprplus,'g-','LineWidth',1); 
% % plot(asset,A,'k--',asset, Apr,'b-','LineWidth',2); 
% % ylabel(' A next'); 
% % xlabel('Total debt/Y'); 
% % %title('(a) Initial prices ');
% % title('Debt service next period'); %(mydata.textdata(1,1));
% % legend ('diag', 'y=z1','Location','northwest');
% % %axis([-.01 amax, -.1 .9 ]);
% % axis([amin amax, zmin zmax]);
% % %%**print -djpeg slides\Apr_z1.jpg




% % Default
% 
% zmin=0.00
% figure(1); 
% subplot(1,1,1);
% %plot(asset,A,'k--',asset, def,'r-',asset, defminus,'b-',asset, defplus,'g-','LineWidth',1); 
% plot(asset,A,'k--',asset, def,'b-','LineWidth',2); 
% ylabel(' default'); 
% xlabel('Debt A'); 
% %title('(a) Initial prices ');
% title(mydata.textdata(1,1));
% legend ('diag', 'y=z');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% print -djpeg slides\def_z1.jpg
% 
% % Borrowing
% 
% zmin=-0.011
% zmax= 0.0200  %0.135
% figure(1); 
% subplot(1,1,1);
% %plot(asset, b,'r-',asset, bminus,'b-',asset, bplus,'g-','LineWidth',1); 
% plot(asset, b,'b-','LineWidth',2); 
% ylabel(' new debt liability B'); 
% xlabel('Debt A'); 
% %title('(a) Initial prices ');
% title(mydata.textdata(1,1));
% legend ('y=z');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% print -djpeg slides\b_z1.jpg
% 
% % Value function
% 
% zmin =-123 
% zmax =-116 
% figure(1); 
% subplot(1,1,1);
% %plot(asset, v,'b-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
% plot(asset, v,'b-','LineWidth',2); 
% ylabel(' value'); 
% xlabel('Debt A'); 
% %title('(a) Initial prices ');
% title(mydata.textdata(1,1));
% legend ('y=z');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% print -djpeg slides\v_z1.jpg

% --------------------------------------
% For various z
% --------------------------------------

mydata = importdata('dataf\d2Apr_z3.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
Aprz3=   mydata.data(:,2)*debtfactor;
defz3=   mydata.data(:,3);
bz3=   mydata.data(:,4);
vz3=   mydata.data(:,6);
qz3=   mydata.data(:,5);
az3=   mydata.data(:,1);

mydata = importdata('dataf\d2Apr_z5.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
Aprz5=   mydata.data(:,2)*debtfactor;
defz5=   mydata.data(:,3);
bz5=   mydata.data(:,4);
vz5=   mydata.data(:,6);
qz5=   mydata.data(:,5);
az5=   mydata.data(:,1);

mydata = importdata('dataf\d2Apr_z6.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
Aprz6=   mydata.data(:,2)*debtfactor;
defz6=   mydata.data(:,3);
bz6=   mydata.data(:,4);
vz6=   mydata.data(:,6);
qz6=   mydata.data(:,5);
az6=   mydata.data(:,1);

mydata = importdata('dataf\d2Apr_z9.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
Aprz9=   mydata.data(:,2)*debtfactor;
defz9=   mydata.data(:,3);
bz9=   mydata.data(:,4);
vz9=   mydata.data(:,6);


mydata = importdata('dataf\d2Apr_z1.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;
Aprz1=   mydata.data(:,2)*debtfactor;
defz1=   mydata.data(:,3);
bz1=   mydata.data(:,4);
vz1=   mydata.data(:,6);

% Debt service

% zmin = 0.00;
% zmax = 0.08; 
% figure(1); 
% subplot(1,1,1);
% %plot(asset,A,'k--',asset, Apr,'r-',asset, Aprminus,'b-',asset, Aprplus,'g-','LineWidth',1); 
% plot(asset,A,'k--',asset, Apr,'b-',asset, Aprz3,'b--',asset, Aprz6,'b-.',asset, Aprz9,'b*-','LineWidth',2); 
% %asset, qq,'b-',asset, qqz3,'b--',asset, qqz6,'b-.',asset, qqz9,'b*-',
% ylabel(' A next'); 
% xlabel('Debt A'); 
% %title('(a) Initial prices ');
% title('Debt service');
% legend ('diag', 'z1', 'z3', 'z6', 'z9');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% print -djpeg slides\Apr_allz.jpg


% Default

zmax=1.1
zmin=0.00
figure(4); 
subplot(1,1,1);
%plot(asset,A,'k--',asset, def,'b-',asset, defz3,'b--',asset, defz6,'b-.',asset, defz9,'b*-','LineWidth',2); 
%***plot(asset, def,'k-',asset, defz3,'r--',asset, defz5,'b-.','LineWidth',2); 
%plot(asset, defz3,'b-',asset, defz5,'r--','LineWidth',2); 
plot(asset, defz1,'k:',asset, defz3,'b-',asset, defz6,'r--','LineWidth',2); 
ylabel(' Partial Default '); 
xlabel('Total debt/Y'); 
%title('(a) Initial prices ');
%title('Default');
legend ('z1','z3', 'z6','Location','northwest');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);
%%**
print -djpeg slides\def_allz.jpg


% % %% Pic1 for paper 
% % zmax=1.1
% % zmin=0.00
% % figure(10);
% % set(gca,'FontSize',18)
% % plot(asset, defz3,'b-',asset, defz5,'r--','LineWidth',2);
% % text(asset(8),defz3(13),'D(A,z3)','FontSize',18,'Color','b')
% % text(asset(15),defz3(8),'D(A,z5)','FontSize',18,'Color','r')
% % ylabel(' Partial Default'); 
% % xlabel('Total Debt to Output'); 
% % axis([amin amax, zmin zmax]);
% % print -depsc slides\default


% Borrowing

zmin=-0.011
zmax= 0.0200  %0.135
% % figure(5); 
% % subplot(1,1,1);
% % %plot(asset, b,'r-',asset, bminus,'b-',asset, bplus,'g-','LineWidth',1); 
% % plot(asset, b,'b-',asset, bz3,'b--',asset, bz9,'r--','LineWidth',2); 
% % ylabel(' new debt liability B'); 
% % xlabel('Total debt/Y'); 
% % %title('(a) Initial prices ');
% % title('Borrowing');
% % legend ('z1', 'z3', 'z6', 'z9');
% % %axis([-.01 amax, -.1 .9 ]);
% % axis([amin amax, zmin zmax]);
% % %%**print -djpeg slides\b_allz.jpg



% Value function

zmin =-123 
zmax =-106 
% % figure(6); 
% % subplot(1,1,1);
% % %plot(asset, v,'b-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
% % plot(asset, v,'b-',asset, vz3,'b--',asset, vz6,'b-.',asset, vz9,'b*-','LineWidth',2); 
% % ylabel(' value'); 
% % xlabel('Total debt/Y'); 
% % %title('(a) Initial prices ');
% % title('Value function');
% % legend ('z1', 'z3', 'z6', 'z9');
% % %axis([-.01 amax, -.1 .9 ]);
% % axis([amin amax, zmin zmax]);
% % %%**print -djpeg slides\v_allz.jpg


% Portfolio

totborrz3=az3.*defz3+qz3.*bz3
sharedefz3=(az3.*defz3)./totborrz3
totborrz5=az5.*defz5 +qz5.*bz5
sharedefz5=(az5.*defz5)./totborrz5
% % amin=0;
% % amax=1.4;
% % zmin =0 
% % zmax =1.03; 
% % figure(7); 
% % subplot(2,1,2);
% % %plot(asset, v,'b-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
% % plot(az3*debtfactor, sharedefz3,'b-','LineWidth',2); 
% % %hold on;
% % %plot(az5, totborrz5,'b--','LineWidth',2); 
% % ylabel(' share of default'); 
% % xlabel('debt/Y'); 
% % %title('(a) Initial prices ');
% % title('Share default/total borrowing');
% % legend ('z3');
% % %axis([-.01 amax, -.1 .9 ]);
% % axis([amin amax, zmin zmax]);
% % 
% % amin=0;
% % amax=.8;
% % zmin =0.08 
% % zmax =.15; 
% % subplot(2,1,1);
% % %plot(asset, v,'b-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
% % plot(az3*debtfactor, totborrz3,'b-','LineWidth',2); 
% % %hold on;
% % %plot(az5, totborrz5,'b--','LineWidth',2); 
% % ylabel(' total borr'); 
% % xlabel('Debt'); 
% % %title('(a) Initial prices ');
% % title('Total borrowing');
% % legend ('z3');
% % %axis([-.01 amax, -.1 .9 ]);
% % axis([amin amax, zmin zmax]);

%%**print -djpeg slides\portfolio_z3.jpg
%%**savefig(['slides\portfolio_z3.fig'])

amin=0;
amax=1.4;
zmin =0.00 
zmax =.20; 

figure(8); 
%plot(asset, v,'b-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
plot(az3*debtfactor, qz3.*bz3,'b-','LineWidth',2); 
hold on;
plot(az3*debtfactor, az3.*defz3,'r--','LineWidth',2); 
%plot(az5, totborrz5,'b--','LineWidth',2); 
ylabel('resources raised'); 
xlabel('Debt'); 
%title('(a) Initial prices ');
%title('Value borrowed');
legend ('borrowing z3','default z3');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);



print -djpeg slides\portfolio2_z3.jpg
%%**savefig(['slides\portfolio2_z3.fig'])



figure(9); 
%plot(asset, v,'b-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
plot(az6*debtfactor, qz6.*bz6,'b-','LineWidth',2); 
hold on;
plot(az6*debtfactor, az6.*defz6,'r--','LineWidth',2); 
%plot(az5, totborrz5,'b--','LineWidth',2); 
ylabel('resources raised'); 
xlabel('Debt'); 
%title('(a) Initial prices ');
%title('Value borrowed');
legend ('borrowing z6','default z6');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);



%print -djpeg slides\portfolio2_z6.jpg
%%**savefig(['slides\portfolio2_z5.fig'])






return;




% --------------------------------------
mydata = importdata('dataf\d2Apr_z3.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;

asset= mydata.data(:,1);
A= mydata.data(:,1);
Apr=   mydata.data(:,2);
def=   mydata.data(:,3);
b=   mydata.data(:,4);
q=   mydata.data(:,5);
v=   mydata.data(:,6);

Aprminus=   mydata.data(:,7);
defminus=   mydata.data(:,8);
bminus=   mydata.data(:,9);
qminus=   mydata.data(:,10);
vminus=   mydata.data(:,11);

Aprplus=   mydata.data(:,12);
defplus=   mydata.data(:,13);
bplus=   mydata.data(:,14);
qplus=   mydata.data(:,15);
vplus=   mydata.data(:,16);

%Aprplus=   mydata.data(:,8);
%defplus=   mydata.data(:,9);
%vplus=   mydata.data(:,10);


zmin = 0.00;
zmax = 0.16; %0.60; %0.135;

%temp
%zmin = 0.04;
%zmax = 0.06;


figure(1); 
subplot(1,1,1);
plot(asset,A,'k--',asset, Apr,'r-',asset, Aprminus,'b-',asset, Aprplus,'g-','LineWidth',1); 
ylabel(' A next'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('diag', 'y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\Apr_z3.jpg

zmin=0.00
figure(1); 
subplot(1,1,1);
plot(asset,A,'k--',asset, def,'r-',asset, defminus,'b-',asset, defplus,'g-','LineWidth',1); 
ylabel(' default'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('diag', 'y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\def_z3.jpg


zmin=-0.011
zmax= 0.0200  %0.135
figure(1); 
subplot(1,1,1);
plot(asset, b,'r-',asset, bminus,'b-',asset, bplus,'g-','LineWidth',1); 
ylabel(' new debt liability B'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\b_z3.jpg


zmax=20.02;
zmin=.0;
figure(1); 
subplot(1,1,1);
plot(asset, q,'r-',asset, qminus,'b-',asset, qplus,'g-','LineWidth',1); 
ylabel(' price Q'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\qq_z3.jpg

zmin =-70 % -91.5 % -38.0;
zmax =-50 % -83.0 %-35.0;

figure(1); 
subplot(1,1,1);
plot(asset, v,'r-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
ylabel(' value'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\v_z3.jpg


% --------------------------------------
mydata = importdata('dataf\d2Apr_z5.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;

asset= mydata.data(:,1);
A= mydata.data(:,1);
Apr=   mydata.data(:,2);
def=   mydata.data(:,3);
b=   mydata.data(:,4);
q=   mydata.data(:,5);
v=   mydata.data(:,6);

Aprminus=   mydata.data(:,7);
defminus=   mydata.data(:,8);
bminus=   mydata.data(:,9);
qminus=   mydata.data(:,10);
vminus=   mydata.data(:,11);

Aprplus=   mydata.data(:,12);
defplus=   mydata.data(:,13);
bplus=   mydata.data(:,14);
qplus=   mydata.data(:,15);
vplus=   mydata.data(:,16);

%Aprplus=   mydata.data(:,8);
%defplus=   mydata.data(:,9);
%vplus=   mydata.data(:,10);


zmin = 0.00;
zmax = 0.16; %0.60; %0.135;

%temp
%zmin = 0.04;
%zmax = 0.06;


figure(1); 
subplot(1,1,1);
plot(asset,A,'k--',asset, Apr,'r-',asset, Aprminus,'b-',asset, Aprplus,'g-','LineWidth',1); 
ylabel(' A next'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('diag', 'y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\Apr_z5.jpg

zmin=0.00
figure(1); 
subplot(1,1,1);
plot(asset,A,'k--',asset, def,'r-',asset, defminus,'b-',asset, defplus,'g-','LineWidth',1); 
ylabel(' default'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('diag', 'y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\def_z5.jpg


zmin=-0.011
zmax= 0.0200  %0.135
figure(1); 
subplot(1,1,1);
plot(asset, b,'r-',asset, bminus,'b-',asset, bplus,'g-','LineWidth',1); 
ylabel(' new debt liability B'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\b_z5.jpg


zmax=20.02;
zmin=.0;
figure(1); 
subplot(1,1,1);
plot(asset, q,'r-',asset, qminus,'b-',asset, qplus,'g-','LineWidth',1); 
ylabel(' price Q'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\qq_z5.jpg

zmin =-139 %-70 % -91.5 % -38.0;
zmax =-133 %-58 % -83.0 %-35.0;

figure(1); 
subplot(1,1,1);
plot(asset, v,'r-',asset, vminus,'b-',asset, vplus,'g-','LineWidth',1); 
ylabel(' value'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\v_z5.jpg

% --------------------------------------
mydata = importdata('dataf\d2Apr_z9.dat', ' ', 2);
mydata.data;
mydata;
mydata.textdata;

asset= mydata.data(:,1);
A= mydata.data(:,1);
Apr=   mydata.data(:,2);
def=   mydata.data(:,3);
b=   mydata.data(:,4);
q=   mydata.data(:,5);
v=   mydata.data(:,6);

Aprminus=   mydata.data(:,7);
defminus=   mydata.data(:,8);
bminus=   mydata.data(:,9);
qminus=   mydata.data(:,10);
vminus=   mydata.data(:,11);

Aprplus=   mydata.data(:,12);
defplus=   mydata.data(:,13);
bplus=   mydata.data(:,14);
qplus=   mydata.data(:,15);
vplus=   mydata.data(:,16);

%Aprplus=   mydata.data(:,8);
%defplus=   mydata.data(:,9);
%vplus=   mydata.data(:,10);


zmin = 0.00;
zmax = 0.16; %0.60; %0.135;

zmin=0.00
figure(1); 
subplot(1,1,1);
plot(asset,A,'k--',asset, def,'r-',asset, defminus,'b-',asset, defplus,'g-','LineWidth',1); 
ylabel(' default'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('diag', 'y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\def_z9.jpg



zmin=-0.011
zmax= 0.0200  %0.135
figure(1); 
subplot(1,1,1);
plot(asset, b,'r-',asset, bminus,'b-',asset, bplus,'g-','LineWidth',1); 
ylabel(' new debt liability B'); 
xlabel('Debt A'); 
%title('(a) Initial prices ');
title(mydata.textdata(1,1));
legend ('y=z', 'y low', 'y high');
%axis([-.01 amax, -.1 .9 ]);
axis([amin amax, zmin zmax]);

print -djpeg slides\b_z9.jpg

return

% % *****************************************
% % ALL SLIDES TOGETHER (narrower domain)
% % *****************************************
% amin= 0.03;
% amax= 0.06;
% 
% 
% mydata = importdata('dataf\d2Apr_z5.dat', ' ', 2);
% mydata.data;
% mydata;
% mydata.textdata;
% 
% asset= mydata.data(:,1);
% A= mydata.data(:,1);
% Apr=   mydata.data(:,2);
% def=   mydata.data(:,3);
% v=   mydata.data(:,4);
% 
% Aprplus=   mydata.data(:,5);
% defplus=   mydata.data(:,6);
% vplus=   mydata.data(:,7);
% 
% Aprminus=   mydata.data(:,8);
% defminus=   mydata.data(:,9);
% vminus=   mydata.data(:,10);
% 
% zmin = 0.03;
% zmax = 0.07;
% figure(1); 
% subplot(3,1,1);
% plot(asset,A,'k--',asset, Apr,'r-',asset, Aprminus,'b-','LineWidth',1); 
% ylabel(' A next'); 
% xlabel('Debt A'); 
% %title('(a) Initial prices ');
% title(mydata.textdata(1,1));
% legend ('diag', 'y=z', 'y=z-2 sd');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% 
% %print -djpeg slides\Apr_z5.jpg
% 
% zmin = 0.00;
% zmax = 0.07;
% %figure(1); 
% subplot(3,1,2);
% plot(asset,A,'k--',asset, def,'r-',asset, defminus,'b-','LineWidth',1); 
% ylabel(' default'); 
% xlabel('Debt A'); 
% %title('(a) Initial prices ');
% title(mydata.textdata(1,1));
% legend ('diag', 'y=z', 'y=z-2 sd');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% 
% %print -djpeg slides\def_z5.jpg
% 
% 
% zmin = -75.0;
% zmax = -70.00;
% %figure(1); 
% subplot(3,1,3);
% plot(asset, v,'r-',asset, vminus,'b-','LineWidth',1); 
% ylabel(' value'); 
% xlabel('Debt A'); 
% %title('(a) Initial prices ');
% title(mydata.textdata(1,1));
% legend ('y=z', 'y=z-2 sd');
% %axis([-.01 amax, -.1 .9 ]);
% axis([amin amax, zmin zmax]);
% 
% print -djpeg slides\all_z5.jpg
% 
